package cn.buk.tms.entity.order.flight;

import com.fasterxml.jackson.annotation.JsonFormat;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;
import jakarta.persistence.CascadeType;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.OneToMany;
import jakarta.persistence.Table;
import jakarta.persistence.Temporal;
import jakarta.persistence.TemporalType;

/**
 * @author yfdai
 * @description 机票追位订单
 */
@Entity
@Table(name="flight_catch_order")
public class FlightCatchOrder {

    public static final int STATUS_CANCELED = 4;
    public static final int STATUS_WAITING = 0;
    public static final int STATUS_PROCESSING = 1;
    public static final int STATUS_DONE = 2;

    /**
     * 订单 ID
     */
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private int id;


    @Column(name = "enterprise_id")
    private int enterpriseId;

    /**
     * 旧的编码
     */
    @Column(name = "old_pnr_no", length = 10)
    private String oldPnrNo;

    /**
     * 新的编码
     */
    @Column(name = "new_pnr_no", length = 10)
    private String newPnrNo;

    /**
     * 新编码需要授权的officeNo
     */
    @Column(name = "auth_office_no", length = 6)
    private String authOfficeNo;


    /*
     * 订单状态
		4 - 已取消
		0 - 待处理
		1 - 处理中
		2 - 已完成
     */
    private int status;

    /**
     * 监控类型
     * 0 - 无
     * 1 - HX/NO 提醒
     * 2 - 追位
     * 3 - 关舱（舱位状态为Q）提醒
     */
    private int monitoring;

    @Column(length = 20, name = "link_phone")
    private String linkPhone;

    /**
     * 备注
     */
    @Column(length = 200)
    private String remark;


    /**
     * 保存航班信息
     */
    @OneToMany(mappedBy = "order", cascade = {CascadeType.ALL}, fetch = FetchType.EAGER)
    private Set<FlightCatchOrderFlight> flights;

    /**
     * 保存乘机人信息和票号
     */
    @OneToMany(mappedBy = "order", cascade = {CascadeType.ALL}, fetch = FetchType.EAGER)
    private Set<FlightCatchOrderPassenger> passengers;


    /**
     * 是否国际票
     * 0 - 否
     * 1 - 是
     */
    @Column(name = "intl_ticket")
    private int intlTicket;

    /**
     * 监控次数
     */
    @Column(name = "try_count")
    private Integer tryCount;

    /**
     * 是否日夜兼程
     * 0-否
     * 1-是
     */
    @Column(name = "day_and_night")
    private Integer dayAndNight;


    /*
     * 订单生成时间，用系统默认时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @Temporal(TemporalType.TIMESTAMP)
    @Column(name = "create_time", insertable = false, updatable = false)
    private Date createTime;

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @Temporal(TemporalType.TIMESTAMP)
    @Column(name = "last_update", insertable = false)
    private Date lastUpdate;

    public int getEnterpriseId() {
        return enterpriseId;
    }

    public void setEnterpriseId(int enterpriseId) {
        this.enterpriseId = enterpriseId;
    }

    public String getOldPnrNo() {
        return oldPnrNo == null ? "" : oldPnrNo.trim();
    }

    public void setOldPnrNo(String oldPnrNo) {
        this.oldPnrNo = oldPnrNo;
    }

    public String getNewPnrNo() {
        return newPnrNo;
    }

    public void setNewPnrNo(String newPnrNo) {
        this.newPnrNo = newPnrNo;
    }

    public int getStatus() {
        return status;
    }

    public void setStatus(int status) {
        this.status = status;
    }

    public int getMonitoring() {
        return monitoring;
    }

    public void setMonitoring(int monitoring) {
        this.monitoring = monitoring;
    }

    public String getLinkPhone() {
        return linkPhone;
    }

    public void setLinkPhone(String linkPhone) {
        this.linkPhone = linkPhone;
    }

    public String getRemark() {
        return remark;
    }

    public void setRemark(String remark) {
        this.remark = remark;
    }

    public Set<FlightCatchOrderFlight> getFlights() {
        if (flights == null) {
            this.flights = new HashSet<>();
        }
        return flights;
    }

    public void setFlights(Set<FlightCatchOrderFlight> flights) {
        this.flights = flights;
    }

    public Set<FlightCatchOrderPassenger> getPassengers() {
        if (passengers == null) {
            this.passengers = new HashSet<>();
        }
        return passengers;
    }

    public void setPassengers(Set<FlightCatchOrderPassenger> passengers) {
        this.passengers = passengers;
    }

    public int getIntlTicket() {
        return intlTicket;
    }

    public void setIntlTicket(int intlTicket) {
        this.intlTicket = intlTicket;
    }

    public Date getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    public Date getLastUpdate() {
        return lastUpdate;
    }

    public void setLastUpdate(Date lastUpdate) {
        this.lastUpdate = lastUpdate;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getAuthOfficeNo() {
        return authOfficeNo == null ? "" : authOfficeNo.trim();
    }

    public void setAuthOfficeNo(String authOfficeNo) {
        this.authOfficeNo = authOfficeNo;
    }

    public int getTryCount() {
        return tryCount == null ? 0 : tryCount;
    }

    public void setTryCount(int tryCount) {
        this.tryCount = tryCount;
    }

    public int getDayAndNight() {
        return dayAndNight == null ? 0 : dayAndNight;
    }

    public void setDayAndNight(Integer dayAndNight) {
        this.dayAndNight = dayAndNight;
    }
}
